package main

import (
	"fmt"
	// "gorm.io/driver/sqlite"
	"github.com/glebarez/sqlite" // 跨平台
	"gorm.io/gorm"
)

type Product struct {
	gorm.Model
	Code  string
	Price uint
}

func main() {
	db, err := gorm.Open(sqlite.Open("test.db"), &gorm.Config{})
	if err != nil {
		panic("failed to connect database")
	}
	err2 := db.AutoMigrate(&Product{})
	if err2 != nil {
		return
	}
	db.Create(&Product{
		Code:  "D41",
		Price: 100,
	})
	var product Product
	db.First(&product, 1)
	fmt.Printf("product code = %s", product.Code)
}
